package com.yhj.wchat.service.impl;

import java.util.Collections;
import java.util.List;

import javax.annotation.Resource;

import com.yhj.wchat.entity.query.PageSize;
import com.yhj.wchat.entity.vo.ContactQunVO;
import com.yhj.wchat.mapper.QunInfoMapper;
import org.springframework.stereotype.Service;


import com.yhj.wchat.entity.query.QunInfoQuery;
import com.yhj.wchat.entity.po.QunInfo;
import com.yhj.wchat.entity.vo.PaginationResultVO;
import com.yhj.wchat.entity.query.SimplePage;

import com.yhj.wchat.service.QunInfoService;
import com.yhj.wchat.utils.StringTools;


/**
 *  业务接口实现
 */
@Service("qunInfoService")
public class QunInfoServiceImpl implements QunInfoService {

	@Resource
	private QunInfoMapper<QunInfo, QunInfoQuery> qunInfoMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<QunInfo> findListByParam(QunInfoQuery param) {
		return this.qunInfoMapper.selectList(param);
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public Integer findCountByParam(QunInfoQuery param) {
		return this.qunInfoMapper.selectCount(param);
	}

	/**
	 * 分页查询方法
	 */
	@Override
	public PaginationResultVO<QunInfo> findListByPage(QunInfoQuery param) {
		int count = this.findCountByParam(param);
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
		param.setSimplePage(page);
		List<QunInfo> list = this.findListByParam(param);
		PaginationResultVO<QunInfo> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(QunInfo bean) {
		return this.qunInfoMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<QunInfo> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.qunInfoMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<QunInfo> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.qunInfoMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 多条件更新
	 */
	@Override
	public Integer updateByParam(QunInfo bean, QunInfoQuery param) {
		StringTools.checkParam(param);
		return this.qunInfoMapper.updateByParam(bean, param);
	}

	/**
	 * 多条件删除
	 */
	@Override
	public Integer deleteByParam(QunInfoQuery param) {
		StringTools.checkParam(param);
		return this.qunInfoMapper.deleteByParam(param);
	}

	/**
	 * 根据QunId获取对象
	 */
	@Override
	public QunInfo getQunInfoByQunId(String qunId) {
		return this.qunInfoMapper.selectByQunId(qunId);
	}

	/**
	 * 根据QunId修改
	 */
	@Override
	public Integer updateQunInfoByQunId(QunInfo bean, String qunId) {
		return this.qunInfoMapper.updateByQunId(bean, qunId);
	}

	/**
	 * 根据QunId删除
	 */
	@Override
	public Integer deleteQunInfoByQunId(String qunId) {
		return this.qunInfoMapper.deleteByQunId(qunId);
	}

	@Override
	public List<ContactQunVO> getQunInfoByQunIds(List<String> qunIds) {
		List<ContactQunVO> qunVOS = qunInfoMapper.getQunInfoByQunIds(qunIds);
		return qunVOS;
	}
}